var ct_type1, ct_size1;
var containers1;
function getDropdownValueCt(url) {
    var tmp = new Array();
    $.ajax({
        url: url, async: false,
        success: function (data, textStatus, jqXHR) {
            $.each(data.results, function (i, n) {
                tmp.push(n[0]);
            });
        }
    });
    return tmp;
}
function initDropdown() {
    var typeobj = $("#containers1 li:first span .ct_type1:not(.ui-autocomplete-input)")
        .autocomplete({
            source: ct_type1,
            minLength: 0,
            open: function (event, ui) {
                $(this).autocomplete("widget").find("a")
                    .css("height", "20px");
            }
        });
    var sizeobj = $("#containers1 li:first span .ct_size1:not(.ui-autocomplete-input)")
        .autocomplete({source: ct_size1, minLength: 0});
    $(typeobj).val(ct_type1[1]);//设置默认显示的柜型
    $(sizeobj).val(ct_size1[0]);
    initDropdownEven(typeobj);
    initDropdownEven(sizeobj);
    initDropdownStyle(typeobj);
    initDropdownStyle(sizeobj);

}
function initDropdownEven(obj) {
    $(obj).bind('click', function () {
        $(this).autocomplete('search', '');
    });
    $(obj).bind('focus', function () {
        $(this).autocomplete('search', '');
    });
}
function initDropdownStyle(obj) {
    $(obj).attr("readonly", "readonly");
    $(obj).addClass('ui-state-default ui-corner-all');
    $(obj).css({"margin": "1px", "text-align": "center"});
}
function addCtbookType() {
    var ct_siez2 = $('input[id=ct_size1]').val();
    var ct_type2 = $('input[id=ct_type1]').val();
    $("#containers1 li")
        .first()
        .append("<span class='containerType1'>/<input type='text' class='ct_num1'/><input type='text' class='ct_size1'/><input type='text' class='ct_type1' /></span>");
    var typeobj = $("#containers1 li:first span .ct_type1:not(.ui-autocomplete-input)")
        .autocomplete({
            source: ct_type1,
            minLength: 0,
            open: function (event, ui) {
                $(this).autocomplete("widget").find("a")
                    .css("height", "20px");
            }
        });
    var sizeobj = $("#containers1 li:first span .ct_size1:not(.ui-autocomplete-input)")
        .autocomplete({source: ct_size1, minLength: 0});
    $(typeobj).val(ct_type2);
    $(sizeobj).val(ct_siez2);
    initDropdownEven(typeobj);
    initDropdownEven(sizeobj);
    initDropdownStyle(typeobj);
    initDropdownStyle(sizeobj);
    $("input[id=delbookType]").attr('disabled', false);
}

function delCtBookType() {
    if ($("#containers1 li span").length == 2) {
        $("#containers1 li span:last").remove();
        $('input[id=delbookType]').attr('disabled', true);
    } else if ($("#containers1 li span").length > 2) {
        $("#containers1 li span:last").remove();
        $('input[id=delbookType]').attr('disabled', false);
    } else {
        $('input[id=delbookType]').attr('disabled', true);
    }

}
$(function () {
    ct_type1 = getDropdownValueCt('../base/dropdown-ctType.do');
    ct_size1 = getDropdownValueCt('../base/dropdown-ctSize.do');
    ct_type1 = [" "].concat(ct_type1);
    initDropdown();
    $('input[id=deleteType]').attr('disabled', true);
});





